import { assetManager } from 'cc';
import { Texture2D, Layers, v3 } from 'cc';
import { Label, Sprite, SpriteFrame } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { GGResource } from '../../../framework/core/base/GGResource';
import { UITransform } from 'cc';
import { Size } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('RankItem')
export class RankItem extends Component {
    @property({ type: Node, displayName: "未上榜" })
    noInRank: Node;
    
    @property({ type: Label, displayName: "排名" })
    rankLabel: Label;
    
    @property({ type: Label, displayName: "名字" })
    rankName: Label;
    
    @property({ type: Label, displayName: "关卡" })
    levelLabel: Label;
    
    @property({ type: Sprite, displayName: "背景" })
    rankSp: Sprite;

    @property({ type: Sprite, displayName: "冠军图片" })
    winIcon: Sprite;

    @property({ type: Sprite, displayName: "头像" })
    headIcon: Sprite;

    @property({ type: [SpriteFrame], displayName: "背景图片" })
    rankBgs: SpriteFrame[] = [];
    UpdateInfo(info){
        if(info.rank <= 3){
            let iconName;
            switch (info.rank) {
                case 1:
                    iconName = "guanjun";
                    break;
                case 2:
                    iconName = "yajun";
                    break;
                case 3:
                    iconName = "jijun";
                    break;
                default:
                    break;
            }

            this.rankLabel.string = (350 - parseInt(info.rank)) + ""
            this.rankName.string = info.name
            this.noInRank.getComponent(Label).string = info.rank
            GGResource.load("rank:texture/" + iconName + "/spriteFrame", SpriteFrame).then((res:SpriteFrame) => {
                this.winIcon.spriteFrame = res;
            });
            //this.winIcon.getComponent(UITransform).contentSize = new Size(70, 77);
        }
        else{
            this.noInRank.getComponent(Label).string = info.rank
            this.noInRank.active = true;
            this.rankName.string = info.name
            this.rankLabel.string = (350 - parseInt(info.rank)) + ""
        }

        
        GGResource.load("rank:texture/heads/icon" + info.rank + "/spriteFrame", SpriteFrame).then((res:SpriteFrame) => {
            this.headIcon.spriteFrame = res;
        });
    }
}


